package com.isunland.managesystem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.amulyakhare.textdrawable.TextDrawable;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseMultiChoiceAdapter;
import com.isunland.managesystem.entity.rContractListMain;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;
import java.util.Map;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/7/25 14:36
 */
public class ContractMultiListAdapter extends BaseMultiChoiceAdapter<rContractListMain> {

  public ContractMultiListAdapter(Context context, ArrayList<rContractListMain> objects,
      Map<rContractListMain, Boolean> selects) {
    super(context, objects, selects);
  }

  @Override protected int getViewRootId() {
    return R.layout.adapter_contact_multi;
  }

  @NonNull @Override public BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override protected void init(rContractListMain object, BaseViewHolder holder, int position) {
    ((ViewHolder) holder).tvTitle.setText(object.getContractName());//合同名
    ((ViewHolder) holder).tvContent1.setText(object.getContractKindName());//合同类别
    ((ViewHolder) holder).tvContent2.setText(object.getContractCode());//合同编码
    ((ViewHolder) holder).tvContent3.setText(object.getPartName());//客户
    ((ViewHolder) holder).tvBottom.setText(MyStringUtil.connect(object.getSignManName(), "   ",
        object.getContractSignDate()));//负责人,签订日期
    ((ViewHolder) holder).ivLogo.setImageDrawable(TextDrawable.builder()
        .buildRound(MyStringUtil.substring(object.getContractKindName(), 0, 2),//合同类别
            context.getResources().getColor(R.color.primary)));
  }

  class ViewHolder extends BaseViewHolder {
    @BindView(R.id.iv_logo) ImageView ivLogo;
    @BindView(R.id.tv_title) TextView tvTitle;
    @BindView(R.id.tv_content1) TextView tvContent1;
    @BindView(R.id.tv_content2) TextView tvContent2;
    @BindView(R.id.tv_content3) TextView tvContent3;
    @BindView(R.id.tv_bottom) TextView tvBottom;
    @BindView(R.id.cb_select) CheckBox cbSelect;

    ViewHolder(View view) {
      super(view);
      ButterKnife.bind(this, view);
    }

    @Override protected int setCheckBoxId() {
      return R.id.cb_select;
    }
  }
}
